﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TLib.Xna;

namespace COMP477_Scorchery
{
    class Map : GeometricPrimitive
    {
        private Vector2 topLeft = new Vector2(0.0f, 0.0f);
        private Vector2 topRight = new Vector2(1.0f, 0.0f);
        private Vector2 bottomLeft = new Vector2(0.0f, 1.0f);
        private Vector2 bottomRight = new Vector2(1.0f, 1.0f);

        public Map(GraphicsDevice graphicsDevice, int rows, int columns, float size, Texture2D texture)
        {
            for (int r = 0; r < rows; r++)
            {
                for (int c = 0; c < columns; c++)
                {
                    //Add vertices
                    AddVertex(new Vector3(((r - ((float)rows / 2)) * size) + size, 0, (c - ((float)columns / 2)) * size), Vector3.Up, topLeft);
                    AddVertex(new Vector3((r - ((float)rows / 2)) * size, 0, (c - ((float)columns / 2)) * size), Vector3.Up, bottomLeft);
                    AddVertex(new Vector3((r - ((float)rows / 2)) * size, 0, ((c - ((float)columns / 2)) * size) + size), Vector3.Up, bottomRight);
                    AddVertex(new Vector3(((r - ((float)rows / 2)) * size) + size, 0, ((c - ((float)columns / 2)) * size) + size), Vector3.Up, topRight);

                    //Add indices
                    int topLeftIndex = (r * columns * 4) + (c * 4);

                    AddIndex(topLeftIndex);
                    AddIndex(topLeftIndex + 2);
                    AddIndex(topLeftIndex + 1);

                    AddIndex(topLeftIndex);
                    AddIndex(topLeftIndex + 3);
                    AddIndex(topLeftIndex + 2);
                }
            }

            InitializePrimitive(graphicsDevice, texture);
        }
    }
}
